package com.aba.hos.doc.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * 病房实体类，管理病房信息和入住病人
 */
public class Ward {
    private static int nextWardNumber = 101;
    private final int wardNumber;
    private final String type;
    private final int capacity;
    private List<Patient> patients;

    public Ward(String type, int capacity) {
        this.wardNumber = nextWardNumber++;
        this.type = type;
        this.capacity = capacity;
        this.patients = new ArrayList<>(capacity);
    }

    // Getters and Setters
    public int getWardNumber() {
        return wardNumber;
    }

    public String getType() {
        return type;
    }

    public int getCapacity() {
        return capacity;
    }

    public List<Patient> getPatients() {
        return patients;
    }

    public int getAvailableBeds() {
        return capacity - patients.size();
    }

    public boolean addPatient(Patient patient) {
        if (patients.size() < capacity && !patients.contains(patient)) {
            patients.add(patient);
            patient.setWard(this);
            return true;
        }
        return false;
    }

    public void removePatient(Patient patient) {
        patients.remove(patient);
        if (patient.getWard() == this) {
            patient.setWard(null);
        }
    }

    @Override
    public String toString() {
        return "Ward{wardNumber=" + wardNumber +
                ", type='" + type + '\'' +
                ", capacity=" + capacity +
                ", availableBeds=" + getAvailableBeds() +
                ", patientsCount=" + patients.size() +
                '}';
    }
}    